/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AulesFrame.java
 *
 * Created on 27-nov-2011, 17:40:24
 */
package edu.uoc.tdp.pac4.only5.gui.client;
import edu.uoc.tdp.pac4.only5.domain.EnumRole;
import edu.uoc.tdp.pac4.only5.gui.client.panels.aules.ConsultaAulesPanel;

import edu.uoc.tdp.pac4.only5.manager.BookingManager;
import edu.uoc.tdp.pac4.only5.manager.UserManager;
import edu.uoc.tdp.pac4.only5.manager.ResourceManager;
import edu.uoc.tdp.pac4.only5.manager.SpaceManager;
import edu.uoc.tdp.pac4.only5.manager.PaymentManager;


import edu.uoc.tdp.pac4.only5.manager.impl.BookingManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.DataBaseConnectionManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.SpaceManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.UserManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.ResourceManagerImpl;
import edu.uoc.tdp.pac4.only5.manager.impl.PaymentManagerImpl;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.rmi.RemoteException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Rafa
 */
public class AulesFrame extends javax.swing.JFrame {
    private static ResourceBundle resourceBundle;
    /** Creates new form AulesFrame */
    private ConsultaAulesPanel consultaAulesPanel;
    
    private BookingManager bookingManager;
    private SpaceManager spaceManager;
    private UserManager userManager;
    private ResourceManager resourceManager;
    private PaymentManager paymentManager;
    
    public AulesFrame() {
        initComponents();
        
        this.setLayout(new FlowLayout());
        resourceBundle = ResourceBundle.getBundle("edu.uoc.tdp.pac4.only5.gui.client.Client");
        setLabels();
        configureViewDependsOfRole();
        try 
        {
            bookingManager = new BookingManagerImpl(DataBaseConnectionManagerImpl.getInstance());
            spaceManager = new SpaceManagerImpl(DataBaseConnectionManagerImpl.getInstance());
            userManager = new UserManagerImpl(DataBaseConnectionManagerImpl.getInstance());
            resourceManager = new ResourceManagerImpl(DataBaseConnectionManagerImpl.getInstance());
            paymentManager = new PaymentManagerImpl(DataBaseConnectionManagerImpl.getInstance());
        } 
        catch (RemoteException ex) {
            //TODO: handle errors!!!
            Logger.getLogger(AulesFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        mnu_ConsultaAules = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jMenu1.setText("Sistema Aules");

        mnu_ConsultaAules.setText("Consulta Aules");
        mnu_ConsultaAules.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnu_ConsultaAulesActionPerformed(evt);
            }
        });
        jMenu1.add(mnu_ConsultaAules);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnu_ConsultaAulesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnu_ConsultaAulesActionPerformed
        // TODO add your handling code here:
        desactivarPanels();
        consultaAulesPanel = new ConsultaAulesPanel(bookingManager,spaceManager,userManager,resourceManager ,paymentManager);
        this.add(consultaAulesPanel, BorderLayout.CENTER);
        this.pack();
    }//GEN-LAST:event_mnu_ConsultaAulesActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AulesFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AulesFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AulesFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AulesFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
 
            @Override
            public void run() {
                new AulesFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JMenuItem mnu_ConsultaAules;
    // End of variables declaration//GEN-END:variables

  
 private void setLabels() {
        mnu_ConsultaAules.setText(getText("mnu_consultaAules"));
        
    }

    private String getText(String key) {
        return resourceBundle.getString(key);
    }

    private void desactivarPanels() {
        
        if(ClientSession.getInstance().getRole() != null){
            if(ClientSession.getInstance().getRole().equals(EnumRole.TECNIC))
                mnu_ConsultaAules.setEnabled(true);
        }
        
        
        
        try {
            this.remove(consultaAulesPanel);
        } catch (Exception e) {
        }

        
    }

 private void configureViewDependsOfRole() {
        EnumRole role = ClientSession.getInstance().getRole();
        
        if(role.equals(EnumRole.TECNIC)){
            mnu_ConsultaAules.setEnabled(true);
        }

}
}
